/*
 * ComponentManager.h
 */
#ifndef _COMPONENT_MANAGER_H_
#define _COMPONENT_MANAGER_H_

#include <allegro.h>
#include "defs.h"
#include "Container.h"

namespace gui
  {
    class Component;

    class ComponentManager : public Container
      {
        static ComponentManager* _instance;

        /** buffer for hit testing */
        BITMAP* _mask;

        Component* _focused;
        int _count;

        int _previous_mouse_b;

        void checkFocus();
        Component* hitTest(Container* container, int hit_id, int x, int y) const;

        ComponentManager();
        
      public:

        static ComponentManager* instance();

        virtual void init();
        virtual void process();

        virtual void paint(BITMAP* buffer);
        virtual void paint(BITMAP* buffer, int x_offset, int y_offset);

        virtual void mask(BITMAP* buffer, int x_offset, int y_offset);

        Component* hitTest(int x, int y) const;

        Component* focused() const;
        bool const focus(Component* comp);
      };
  }

#endif
